const Mytopic = require('../model/mytopic')

/**
 * 学生选题中间件
 */
module.exports = {
    /**
     * 学生选的题目的信息
     */
    getListByUid: (req, res, next) => {
        let uid = req.params.uid
        Mytopic.getListByUid(uid).then(results => {
            req.mytopics = results
            next()
        }).catch(err => {
            next(err)
        })
    },
    /**
     * 学生选题信息
     */
    getInfoByUid: (req, res, next) => {
        let uid = req.params.uid
        Mytopic.getInfoByUid(uid).then(results => {
            req.info = results
            next()
        }).catch(err => {
            next(err)
        })
    },
    /**
     * 添加学生选题
     */
    addAid: (req, res, next) => {
        let {aid,aid2,aid3,uid} = req.body
        Mytopic.addAid(aid, aid2, aid3, uid).then(results => {
            req.affectedRows = results
            next()
        }).catch(err => {
            next(err)
        })
    },
    /* 
        获取结果
    */
    getres: (req, res, next) => {
        let uid = req.params.uid
        Mytopic.getres(uid).then(results => {
            req.getres = results
            next()
        }).catch(err => {
            next(err)
        })
    }
}